const util = require('../../utils/util.js');
import api from '../../utils/request/api'
import {
	goodsList,
	getBanner,
	getsort,
	getsortAll,
  Ticket, userCenter, getCartDetailList, addGoodsOfCart
} from '../../utils/request/apiurl'
var app = getApp();
Page({
	data: {
		imgUrls: [],
		currentNav: 0,
		currentId: 0,
		navList: [],
		isClassOpen: false,
		currentClassName: '综合分类',
		radioItems: [],
		listScreen: {
			classId: 1
		},
		salesVolumeIndex: 0,
		priceIndex: 0,
		isRequest: false,
		searchGood: {
			page: 1,
			size: 10,
			pages: 0 //总页数
		},
		goodList: [],
		isPopUp: true,
		scrollLeft: 0, //tab标题的滚动条位置
		couponList: [], //优惠券列表
		rank: 0,
		goodPrice: 0, //商品价格
		link: 0, //0未领取优惠券，1已经领过
		uid: '',
		tid: '', //优惠券id
		fsortId: '', //一级
		sortId: '', //二级
		orderBy: '',
		scrollTop: '', //滑动的距离
		navFixed: false, //导航是否固定
		userData:{},
    shopIndex:0,//商品index\
    shopTabId:null,//是够确认添加购物车id
	},
	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function(options) {

		// console.log(options.goodId,'khgyhftgdrmtd')
		// if(options.goodId!=undefined){
		// 	wx.navigateTo({
		// 		url: '../good-detail/good-detail?goodId='+options.goodId+'&type=0'
		// 	})
		// }
    console.log("========>",options)
		if (options != undefined) {
			var user = {}
			user['TJuid'] = options.uid //推荐人uid
			wx.setStorageSync('user', user);
		}
		if (wx.getStorageSync('userInfo') != '') {
			this.getData()
			var userInfo = wx.getStorageSync('userInfo');
			this.setData({
				uid: userInfo.uid,
				rank: userInfo.rank,
				link: userInfo.link, //0未领取优惠券，1已经领过
			})
		}
		this.getGoodList();
		this.getBanner();
		this.getSortList();
		wx.showTabBar()

		wx.getSystemInfo({
			success: (res) => {
				this.setData({
					pixelRatio: res.pixelRatio,
					windowHeight: res.windowHeight,
					windowWidth: res.windowWidth
				})
			},
		})
	},
  onShow: function () {
		// wx.getShareInfo({
		// 	withShareTicket: true
		// }),
		this.TicketList()
		if (wx.getStorageSync('userInfo') != '') {
			this.getData()
			var userInfo = wx.getStorageSync('userInfo');
			this.setData({
				// goodList: [],
				uid: userInfo.uid,
				rank: userInfo.rank,
				link: userInfo.link, //0未领取优惠券，1已经领过
			})
			if (this.data.link == 1) {
				this.setData({
					isPopUp: true,
				})
				// this.TicketList()
				wx.showTabBar();
			} else if (this.data.link == 0 && this.data.couponList.length != 0) {
				wx.hideTabBar()
				this.setData({
					isPopUp: false,
				})
			} else {
				wx.showTabBar();
				this.setData({
					isPopUp: false,
				})
			}
    }
    if (this.data.goodList.length === 0){
        return
    }
    //重新登录之后执行一次商品列表加载
    //缓存用户是否已经登录
    // wx.setStorageSync('isLogin', true)
    var isLogin = wx.getStorageSync('isLogin');
    console.log("isLogin",isLogin)
    if ( isLogin && isLogin == true){
      // this.getGoodList();//重加载列表
      this.setData({
        goodList: [],
        imgUrls: [],
        searchGood: {
          page: 1,
          size: 10,
          pages: 0 //总页数
        },
      })
      //覆盖缓存值
      wx.setStorageSync('isLogin', false)
      //重新赋值缓存
      wx.setStorageSync('shopObj', {
        shopId: this.data.shopTabId,
        shipIs: true,
      });
      this.onLoad();
    }
    //第一次加入购物车做判断重新渲染数据
    var shopIdObj = wx.getStorageSync('shopObj');
    this.setData({
      shopTabId: Number(shopIdObj.shopId)
    })
    console.log(this.data.goodList,'this.data.goodListthis.data.goodList')
    if (this.data.goodList != '' && this.data.goodList != null && this.data.goodList.length>0&&this.data.goodList[this.data.shopIndex].id === Number(shopIdObj.shopId) && shopIdObj.shipIs == false) {
        this.data.goodList[this.data.shopIndex].goodsCount++;
        for (let i in this.data.goodList) {
          let item = 'goodList[' + this.data.shopIndex + '].goodsCount'
          this.setData({
            [item]: this.data.goodList[this.data.shopIndex].goodsCount	//注意：这里item必须要加[]
          })
        }
        //重新赋值缓存
        wx.setStorageSync('shopObj', {
          shopId: this.data.shopTabId,
          shipIs: true,
        });
      }
	},
	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function() {
		if (!this.data.isRequest && this.data.searchGood.page < this.data.searchGood.pages) {
			this.setData({
				searchGood: {
					page: this.data.searchGood.page + 1,
					size: 10,
					pages: this.data.searchGood.pages
				}
			})
			this.getGoodList(this.data.fsortId)
    }
    console.log("页面触底", this.data.goodList)
	},
  //banner跳转到商品详情页
  imgUrlNav(e) {
    if (e.currentTarget.dataset.goodsid == 0 || e.currentTarget.dataset.goodsid == null){
      return wx.showToast({
            title: "暂无页面跳转",
            icon: 'none'
          })
    }
    let id = e.currentTarget.dataset.goodsid
    wx.navigateTo({ url: '../good-detail/good-detail?shopid=' + id })
  },
  //加入购物车
  addCart(e){
    wx.navigateTo({
      url: '../good-detail/good-detail?goodId=' + e.currentTarget.dataset.goodid + '&type=1'
    })
    //确认用户是否加入购物车
    // if (e.currentTarget.dataset.goodid !== Number(shopIdObj)){
    //   return
    // }
    // let Index = e.currentTarget.dataset.idx
    this.setData({
      shopIndex: e.currentTarget.dataset.idx
    })
    // var source = {}
      // source['cid'] = this.data.goodList[Index].cartId;
    // this.data.goodList[this.data.shopIndex].goodsCount++;
    // this.data.goodList[this.data.shopIndex].goodsCount = this.data.goodList[this.data.shopIndex].goodsCount++;
      // // this.setData({})
      // var shopIdObj = wx.getStorageSync('shopId');
      // for (let i in this.data.goodList) {
      //   if (this.data.goodList.id !== Number(shopIdObj)){
      //     return
      //   }
      //   let item = 'goodList[' + this.data.shopIndex + '].goodsCount'
      //   this.setData({
      //     [item]: this.data.goodList[this.data.shopIndex].goodsCount	//注意：这里item必须要加[]
      //   })
      // }
      // console.log("===========>", this.data.goodList[Index].goodsCount)
      // source['count'] = this.data.goodList[Index].goodsCount;
      //加入购物车调用确认添加购物车接口
    // api.post(addGoodsOfCart.list, source).then(res => {
    //       wx.showToast({
    //         title: "添加成功",
    //         icon: 'none'
    //       })
    //   }).catch(err => {
    //     console.log(err)
    //     wx.showToast({
    //       title: err.message,
    //       icon: 'none'
    //     })
    //   })
  },
  //点击加减按钮  
  numchangeTap: function (e) {
    let Index = e.currentTarget.dataset.index
    //是加号还是减号  
     let types = e.currentTarget.dataset.types      
    var source = {}
    if (types == 'add') {

      console.log(this.data.goodList[Index], 'this.data.goodList[Index].goodsCount')
      // if (this.data.goodList[Index].cardSku != null && this.data.goodList[Index].cardSku!=''){
      //   source['cid'] = this.data.goodList[Index].cardSku;  
      // }else{
      //   source['cid'] = this.data.goodList[Index].cartId;  
      // }
      source['cid'] = this.data.goodList[Index].cartId;     

      this.data.goodList[Index].goodsCount++;
      this.data.goodList[Index].goodsCount = this.data.goodList[Index].goodsCount++;
      // this.setData({})
     
      // for (let i in this.data.goodList) {
      //   let item = 'goodList[' + Index + '].goodsCount'
      //   this.setData({
      //     [item]: this.data.goodList[Index].goodsCount	//注意：这里item必须要加[]
      //   })
      // }
      source['count'] = this.data.goodList[Index].goodsCount;

    } else if (types == 'minus') {
      if (this.data.goodList[Index].goodsCount > 1) {
        this.data.goodList[Index].goodsCount--; //对应商品的数量-1
        for (let i in this.data.goodList) {
          let item = 'goodList[' + Index + '].goodsCount'
          this.setData({
            [item]: this.data.goodList[Index].goodsCount	//注意：这里item必须要加[]
          })
        }
        source['cid'] = this.data.goodList[Index].cartId;
        source['count'] = this.data.goodList[Index].goodsCount
      } else {
        wx.showToast({
          title: '不能再减少了',
          icon: 'none'
        })
        return false
      }
    }
    api.post(getCartDetailList.update, source).then(res => {
      if (types == 'add'){
        wx.showToast({
          title: "添加成功",
          icon: 'none'
        })
        for (let i in this.data.goodList) {
          let item = 'goodList[' + Index + '].goodsCount'
          this.setData({
            [item]: this.data.goodList[Index].goodsCount	//注意：这里item必须要加[]
          })
        }

      } else if(types == 'minus') {


        wx.showToast({
          title: "减少成功",
          icon: 'none'
        })


      }
    }).catch(err => {
      wx.showToast({
      	title: err.message,
      	icon: 'none'
      })
    })
  },
	// 优惠券列表
	TicketList() {
		// var source = {
		// 	page: 1,
		// 	size: 2,
		// }
		api.post(Ticket.list, ).then(res => {
			var list = []
			var res = res
			for (var i = 0; i < res.length; i++) {
				res[i].outTime = util.getLocalDate1(res[i].outTime)
				list.push(res[i])
			}
			this.setData({
				couponList: list,
			})
		}).catch(err => {
			// wx.showToast({
			// 	title: err.message,
			// 	icon: 'none'
			// })
		})
	},
	// 拿banner图
	getBanner() {
		api.post(getBanner.list).then(res => {
			if (res.bannerList < 3) {
				this.setData({
					imgUrls: res.bannerList
				})
			} else {
				this.setData({
					imgUrls: res.bannerList.slice(res.length - 3, res.length)
				})
			}

		}).catch(err => {
			wx.showToast({
				title: err.message,
				icon: 'none'
			})
		})
	},
  onPullDownRefresh: function() {
		wx.showNavigationBarLoading() //在标题栏中显示加载
		this.setData({
			goodList: [],
			imgUrls: [],

			searchGood: {
				page: 1,
				size: 10,
				pages: 0 //总页数
			},
		})
		this.getGoodList();
		this.getBanner();
		// this.getSortList();
		// this.onShow()
		// this.onLoad()
		setTimeout(function() {
			wx.hideNavigationBarLoading() //完成停止加载
			wx.stopPullDownRefresh() //停止下拉刷新
		}, 1500);

	},
	//获取用户信息
	getData() {	
		var source = {
			uid: this.data.uid || wx.getStorageSync('userInfo').uid
		}
		api.post(userCenter.userData, source).then(res => {
			var userInfo=wx.getStorageSync('userInfo')
			userInfo['isColonel'] = res.isColonel;
			userInfo['isRealname'] = res.isRealname;
			userInfo['isPayPassword'] = res.isPayPassword;
			// userInfo['isColonel'] = res.isColonel //0不是团长，1是团长
			userInfo['role'] = res.role; //0不是快递员，1是快递员
			userInfo['phone'] = res.phone;
			wx.setStorageSync('userInfo', userInfo);
			this.setData({
				userData: res,
			})
		}).catch(err => {
			// wx.showToast({
			// 	title: '暂未登录，请前去登录',
			// 	icon: 'none',
			// 	duration: 2000
			// })
		})
	},
	// 获取商品列表
	getGoodList(fsortId) {
		// this.setData({
		// 	isRequest: true
		// })
		// this.setData({
		// 	goodList:[]
		// })
		var _this = this
		var source = {
			page: _this.data.searchGood.page,
			size: _this.data.searchGood.size,
			uid: _this.data.uid
		}
		if (_this.data.fsortId != '') {
			if (_this.data.fsortId != -1) {
				source['fsortId'] = _this.data.fsortId
			}
		}

		if (_this.data.sortId != '') {
			// if(_this.data.sortId != -1){
			source['sortId'] = _this.data.sortId
			source['fsortId'] = _this.data.fsortId
			// }

		}
		//销量排序  2从高到低  3从低到高
		if (_this.data.salesVolumeIndex != 0) {
			if (_this.data.orderBy != '') {
				source['orderBy'] = _this.data.orderBy;
			}
		}
		//价格排序 4从高到低  5从低到高
		if (_this.data.priceIndex != 0) {
			if (_this.data.orderBy != '') {
				var pId = _this.data.orderBy;
				if (pId == 1) {
					source['orderBy'] = 4;
				} else if (pId == 2) {
					source['orderBy'] = 5;
				} else {
					source['orderBy'] = 1;
				}
			}
		}
		api.post(goodsList.list, source).then(res => {
      //得到会员折扣的价格缓存
			// var rankSellcount = wx.getStorageSync('userInfo');
      // if (rankSellcount.sellCount){
      //   for (var i = 0; i < res.rows.length; i++) {
      // //得到会员折扣的价格缓存
      //     res.rows[i]['goodPrice'] = res.rows[i].currentPrice * (rankSellcount.sellCount / 100);
      //   }
      // }else{
        for (var i = 0; i < res.rows.length; i++) {
          // if(this.data.rank==1 && res.rows[i].commonMember!=null){
          // 	res.rows[i]['goodPrice']=res.rows[i].commonMember;
          // }else if(this.data.rank==2 && res.rows[i].middleMember!=null){
          // 	res.rows[i]['goodPrice']= res.rows[i].middleMember;
          // }else if(this.data.rank==3 && res.rows[i].expertMember!=null){
          // 	res.rows[i]['goodPrice']= res.rows[i].expertMember;
          // }else{
          // 	if(res.rows[i].currentPrice==null){
          // 		res.rows[i]['goodPrice']=0
          // 	}else{
          res.rows[i]['goodPrice'] = res.rows[i].currentPrice;
          // 	}
          // }
        }
      // }
			var list = res.rows
			var goodList = this.data.goodList
			for (var i = 0; i < list.length; i++) {

				goodList.push(list[i])
			}
			// this.data.goodList.push(list)

			// this.setData({
			// 	goodList: [...this.data.goodList, ...list],
			// 	// goodList:this.data.goodList
			// })
			let pages = res.total / this.data.searchGood.size
			this.setData({
				searchGood: {
					page: this.data.searchGood.page,
					size: this.data.searchGood.size,
					pages: pages
				},
				goodList: goodList
				// goodList: [...this.data.goodList, ...list],
			})
		}).catch(err => {
			wx.showToast({
				title: err.message,
				icon: 'none'
			})
		})

		// wx.request({
		//   url: 'https://backstage.dfbs-vm.com/boda/goods/getGoodsList',
		//   method:'POST',
		//   // data: options.method === 'GET' ? options.data : JSON.stringify(options.data),
		//   data: source,
		//   header: {
		//     // 'Content-Type': 'application/json; charset=UTF-8',
		// 	'Content-Type': 'application/x-www-form-urlencoded' 
		// 	// "Accept": "*/*",
		//     // 'token': 'token'
		//   },
		//   success(res) {
		// 	  setTimeout(function () {
		// 	    wx.hideLoading()
		// 	  }, 5000)
		// 	  var list = res.data.data.rows
		// 	  var goodList=_this.data.goodList
		// 	  	for(var i=0;i<list.length;i++){
		// 	  		goodList.push(list[i])
		// 	  	}
		// 	  let pages =res.data.data.total / _this.data.searchGood.size
		// 	  	_this.setData({
		// 	  		searchGood: {
		// 	  			page: _this.data.searchGood.page,
		// 	  			size: _this.data.searchGood.size,
		// 	  			pages: pages
		// 	  		},
		// 	  		goodList:goodList
		// 	  		// goodList: [...this.data.goodList, ...list],
		// 	  	})
		//   },
		//   fail(error) {
		//     wx.hideLoading()
		//     reject(error.data)
		//   }
		// })
	},
	// 跳转特价商品
	goGoodSpecial() {
		this.setData({
			isClassOpen: false
		})
		wx.navigateTo({
			url: '../good-special/good-special'
		})
	},
	// 打开分类列表
	openClass() {
		// wx.hideTabBar();
		const current = this.data.isClassOpen;
		this.setData({
			isClassOpen: !current
		})
		if (!this.data.isClassOpen) {
			wx.showTabBar();
		}
	},
	// 关闭分类列表
	closeClass() {
		this.setData({
			isClassOpen: false
		})
		wx.showTabBar();
	},
	// 选择分类
	changeTab(event) {
		this.setData({
			sortId: '',
			isClassOpen: false
		})
		this.setData({
			searchGood: {
				page: 1,
				size: 10,
				pages: 0 //总页数
			},
			goodList: []
		})
		const currentIndex = event.currentTarget.dataset.index;
		const currentId = event.currentTarget.dataset.id;
		// 给当前项增加class
		if (this.data.currentNav !== currentIndex) {
			this.setData({
				currentNav: currentIndex,
				currentId: event.currentTarget.dataset.id,
				currentClassName: '综合分类',
			})
		}
		this.setData({
			fsortId: currentId
		})
		this.checkCor();
		this.getSortListTwo(currentId);
		this.getGoodList(currentId + 'f')

	},
	//判断当前滚动超过一屏时，设置tab标题滚动条。
	checkCor: function() {
		if (this.data.currentNav > 2) {
			this.setData({
				scrollLeft: 45 * (this.data.currentNav)
			})
		} else {
			this.setData({
				scrollLeft: 0
			})
		}
	},
	radioChange: function(e) {
		wx.showTabBar();
		this.setData({
			goodList: [],
			searchGood: {
				page: 1,
				size: 10,
				pages: 0 //总页数
			},
		})
		var arr = e.detail.value.split(',')
		let radioItems = this.data.radioItems;
		for (let i = 0, len = radioItems.length; i < len; ++i) {
			// radioItems[i].checked={};	
			radioItems[i].checked = radioItems[i].id == arr[0];
		}
		this.setData({
			radioItems: radioItems
		})
		const currentClass = this.data.radioItems.find(item => item.checked);

		this.setData({
			currentClassName: currentClass.sortName,
			listScreen: {
				classId: currentClass.id
			},
			isClassOpen: false,
		})
		var parId = currentClass.parId.split(',');

		// if (parId[1] != '') {
		this.setData({
			// sortId: currentClass.id,
			// fsortId:currentClass.fatherSortId
			sortId: parId[0],
			fsortId: parId[1]
		})
		//全部的时候,父级id不为空
		this.getGoodList();
		// } else {
		// 	this.setData({
		// 		sortId: currentClass.id
		// 	})
		// 	//父级为空
		// 	this.getGoodList(parId[0] + 'N')
		// }

	},
	// 切换销量
	salesVolumeChange(e) {
		this.setData({
			goodList: [],
			isClassOpen: false
		})
		let salesVolumeIndex = this.data.salesVolumeIndex;
		this.setData({
			priceIndex: 0
		})
		if (salesVolumeIndex < 2) {
			this.setData({
				salesVolumeIndex: ++salesVolumeIndex
			})
		} else {
			this.setData({
				salesVolumeIndex: 0
			})
		}
		this.setData({
			orderBy: salesVolumeIndex + 1
		})
		this.getGoodList(salesVolumeIndex + 1 + 'S');

	},
	// 切换价格
	priceChange(e) {
		this.setData({
			goodList: [],
			isClassOpen: false
		})
		let priceIndex = this.data.priceIndex;
		this.setData({
			salesVolumeIndex: 0
		})
		if (priceIndex < 2) {
			this.setData({
				priceIndex: ++priceIndex
			})
		} else {
			this.setData({
				priceIndex: 0
			})
		}
		this.setData({
			orderBy: priceIndex
		})
		this.getGoodList(priceIndex + 'P');
	},
	//商品分类navList 一级
	getSortList() {
		var source = {
			type: 0,
			page: this.data.searchGood.page,
			size: this.data.searchGood.size,
		}
		api.post(getsort.list, source).then(res => {
			var all = {};
			all['sortName'] = '全部';
			all['id'] = -1;
			res.list.unshift(all);
			this.setData({
				navList: res.list
			})
			this.getSortListTwo(res.list[0].id);
		}).catch(err => {
			wx.showToast({
				title: err.message,
				icon: 'none'
			})
		})
	},
	getSortListTwo(id) {
		var source = {
			type: 1,
			parentId: id || this.data.currentId,
			page: this.data.searchGood.page,
			size: this.data.searchGood.size,
		}
		if (id == -1) {
			api.post(getsortAll.list).then(res => {
				var res = res
				// var all = {};
				// all['sortName'] = '全部';
				// all['id'] = -1;
				// res.unshift(all);
				for (var i = 0; i < res.length; i++) {
					// var classification = {};
					// classification['id'] = res[i].id;
					// classification['fatherSortId'] = res[i].fatherSortId;

					// if (res[i].fatherSortId != null && res[i].fatherSortId != undefined && res[i].fatherSortId != '') {
					// 有父级
					// if(res[i].id==-1){
					// 	//全部
					// 	res[i].parId = '' + ',' + res[i].fatherSortId
					// }else{
					res[i].parId = res[i].id + ',' + res[i].fid
					// }	
					// } else {
					//没有父级
					// if(res[i].id==-1){
					// 	//全部
					// 	res[i].parId = '' + ',' + ''
					// }else{
					// res[i].parId = res[i].id + ',' + ''
					// }	
					// }
				}
				this.setData({
					radioItems: res
				})
			}).catch(err => {
				wx.showToast({
					title: err.message,
					icon: 'none'
				})
			})
		} else {
			api.post(getsort.list, source).then(res => {
				// var all = {};
				// all['sortName'] = '全部';
				// all['id'] = -1;
				// all['fatherSortId'] = id;
				// res.list.unshift(all);
				var classification = {};
				for (var i = 0, res = res.list; i < res.length; i++) {
					// classification['id'] = res[i].id;
					// classification['fatherSortId'] = res[i].fatherSortId;
					// if(res[i].id==-1){
					// 	res[i].parId = ''+ ',' + res[i].fatherSortId
					// }else{
					res[i].parId = res[i].id + ',' + res[i].fatherSortId
					// }	
				}

				this.setData({
					radioItems: res
				})
			}).catch(err => {
				wx.showToast({
					title: err.message,
					icon: 'none'
				})
			})
		}
	},
	// 跳转搜索
	goSearch() {
		wx.navigateTo({
			url: '../good-search/good-search'
		})
	},
	// 领取优惠券
	handleReceive() {
		if (this.data.couponList.length == 1) {
			var source = {
				tid: parseInt(this.data.couponList[0].id),
				uid: this.data.uid,
			}
		} else if (this.data.couponList.length > 1) {
			var source = {
				tid: this.data.couponList[0].id + ',' + this.data.couponList[1].id,
				uid: this.data.uid,
			}
		}
		api.post(Ticket.receive, source).then(res => {
			// if (res.data > 0) {
			this.setData({
				isPopUp: true,
			})
			// }
			var userInfo = wx.getStorageSync('userInfo')
			userInfo['link'] = 1;
			wx.setStorageSync('userInfo', userInfo);
		}).catch(err => {
			wx.showToast({
				title: err.message,
				icon: 'none'
			})
		})
		wx.showTabBar()
	},
	// 关闭弹窗
	closePopup() {
		this.setData({
			link: 0,
			isPopUp: true,
		})
		wx.showTabBar()
	},
	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function() {
		var that = this
		return {
			// title: '自定义转发标题',
			path: 'pages/home/home?uid=' + that.data.uid,
			success: function(res) {
				var shareTickets = res.shareTickets;
				if (shareTickets.length == 0) {
					return false;
				}
				wx.getShareInfo({
					shareTicket: shareTickets[0],
					success: function(res) {
						var encryptedData = res.encryptedData;
						var iv = res.iv;
					}
				})
			},
			fail: function(res) {
				// 转发失败
			}

		}
	},
	// 加入购物车
	sureAddCar(e) {
		wx.navigateTo({
			url: '../good-detail/good-detail?goodId=' + e.currentTarget.dataset.goodid + '&type=1'
		})
	},
  //滚动到底部触发
  bottomScroll(e) {
    if (!this.data.isRequest && this.data.searchGood.page < this.data.searchGood.pages) {
      this.setData({
        searchGood: {
          page: this.data.searchGood.page + 1,
          size: 10,
          pages: this.data.searchGood.pages
        }
      })
      this.getGoodList(this.data.fsortId)
    }
    console.log("页面触底", this.data.goodList)
    console.log("滚动到底部",1)
  },
	layoutScroll(e) {
    // console.log(e.detail.scrollHeight, e.detail.scrollTop,e.detail.scrollHeight - e.detail.scrollTop)
		this.data.scrollTop = this.data.scrollTop * 1 + e.detail.deltaY * 1;
    if(e.detail.scrollTop == 0){
      wx.showNavigationBarLoading() //在标题栏中显示加载
      this.setData({
        goodList: [],
        imgUrls: [],
        searchGood: {
          page: 1,
          size: 10,
          pages: 0 //总页数
        },
      })
      this.getGoodList();
      this.getBanner();
      this.getSortList();
      // this.getSortList();
      // this.onShow()
      // this.onLoad()
      setTimeout(function () {
        wx.hideNavigationBarLoading() //完成停止加载
        wx.stopPullDownRefresh() //停止下拉刷新
      }, 1500);
    }
		if (this.data.scrollTop <= -160) {
			this.setData({
				navFixed: true
			})
		} else {
			this.setData({
				navFixed: false
			})
			// this.onReachBottom()
    }
	},
	footerTap: app.footerTap
})
